let timeout = false;
let modalParams = {
	_this : null,//当前对象(必填)
	content : '',//提示内容
	title : '提示',//提示标题
	_type : 'info',//弹框类型
	confirmButtonText : '确定',//弹框确定按钮文案
	cancelButtonText : '取消',//弹框取消按钮文案
	inputPattern : '',//正则表达式
	inputErrorMessage : "",//正则匹配错误提示
	successMessage : '操作成功',//操作成功文案
	cancelMessage : '操作取消',//操作取消文案
	actionMessage : '动作'//动作文案
}
/* *
 * prompt模态框，参数详见modalParams对象声明
 * */
function promptModal(modalParams,succCallback,errCallback){
	modalParams._this.$prompt(modalParams.content, modalParams.title, {
      confirmButtonText: modalParams.confirmButtonText,
      cancelButtonText: modalParams.cancelButtonText,
      inputPattern: modalParams.inputPattern,
      inputErrorMessage: modalParams.inputErrorMessage
    }).then(succCallback).catch(errCallback);
    	/*({ value }) => {
	      modalParams._this.$message({
	        type: 'success',
	        message: modalParams.successMessage + value
	      });
	    }*/
    /*).catch(() => {
      modalParams._this.$message({
        type: 'info',
        message: modalParams.cancelMessage
      });       
    });*/
}
/* *
 * alert模态框，参数详见modalParams对象声明
 * */
let alertModal = function (modalParams,callback){
	modalParams._this.$alert(modalParams.content, modalParams.title, {
      confirmButtonText: modalParams.confirmButtonText,
      type: modalParams._type,
      callback: callback/*action => {
        modalParams._this.$message({
          type: 'info',
          message: `${modalParams.actionMessage}: ${ action }`
        });
      }*/
    });
}
/* *
 * confirm模态框，参数详见modalParams对象声明
 * */
let confirmModal = function (modalParams,succCallback,errCallback){
	modalParams._this.$confirm(modalParams.content, modalParams.title, {
      confirmButtonText: modalParams.confirmButtonText,
      cancelButtonText: modalParams.cancelButtonText,
      type: modalParams._type
    }).then(succCallback).catch(errCallback);
    	/*() => {
	      modalParams._this.$message({
	        type: 'success',
	        message: modalParams.successMessage
	      });
    	}*/
    	/*).catch(() => {
      modalParams._this.$message({
        type: 'info',
        message: modalParams.cancelMessage
      });         
	})*/
}

/* *
 * getAjax
 * 参数--必填:obj.url:获取数据的路径
 * 参数--选填:obj.options:包含method、headers、timeout等参数
 * */
let getAjax = (obj) => {
	modalParams._this = obj._this;
	obj._this.$http.get(obj.url,[obj.options]).then(obj.successCallback,function(){	
});
	/*
	 function(res){
		//成功函数
		if(JSON.parse(res.bodyText).statusCode == 302){
			modalParams.content = '用户已被登出，请重新进行登录';
			alertModal(modalParams,function(){
				window.location.href='/';
			});
			//confirmModal(obj._this,'确定要删除此项数据吗？');
		}
	},function(res){
		//失败函数
		if(res.status == 404){
			modalParams.content = obj.error;
			modalParams._type = 'warning';
			alertModal(modalParams);
		}
	}
	 * */
}

/* *
 *
 * */

export default{
	timeout,
	getAjax,
	promptModal,
	alertModal,
	confirmModal,
	modalParams
}
